package com.huonan.jb.tools.command;

import java.util.Optional;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.MissingArgumentException;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class ExtractiEsDataConvertOptions implements ConvertOptions {

    @Override
    public  CommandLine convertArgsToOptions(String[] args) throws ParseException {
        Options options = new Options();
        options.addOption("v", true, "ggg,eg:-v qingbo");
        options.addOption("p", true, "ggg,eg:-p ec");
        BasicParser parser = new BasicParser();
        CommandLine cl = parser.parse(options, args);
        checkOptions(cl);
        return cl;
    }

    public static void checkOptions(CommandLine cl) throws MissingArgumentException {

        Optional.ofNullable(cl.getOptionValue("v")).orElseThrow(() -> new MissingArgumentException("vendor " +
                "不能为空，eg:-v " +
                "ec"));
        Optional.ofNullable(cl.getOptionValue("p")).orElseThrow(() -> new MissingArgumentException("pt " +
                "不能为空，eg:-p " +
                "ec"));
        Optional.ofNullable(cl.getOptionValue("s")).orElseThrow(() -> new MissingArgumentException("source" +
                " " +
                "不能为空，eg:-s " +
                "douyin.com"));
    }
}